<!DOCTYPE html>
<html lang="en">
<!--header-->
<include file="Public:header"/>
<!--header-->
<section id="main-content">
    <section class="wrapper">
        <h3><i class="fa fa-angle-right"></i> 添加/修改首页分类信息</h3>
        <a class="btn btn-theme btn-default" onclick="history.go(-1)">返回</a>

        <!-- BASIC FORM ELELEMNTS -->
        <div class="row mt">
            <div class="col-lg-12">
                <div class="form-panel">
                    <h4 class="mb"><i class="fa fa-angle-right"></i> 首页分类信息</h4>
                    <form id="type" class="form-horizontal style-form" method="post" action=""  enctype="multipart/form-data">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">图标<span style="color: red;">(28px*28px)</span></label>
                            <div class="col-sm-10">
                                <input type="file" name="one" id="avatar" onchange='PreviewImage(this)' style="opacity: 0;display: block;cursor:pointer" />
                                <if condition="$list.img != NULL">
                                    <img class="ph-user"  src="{$list.img}" width="80" height="60" onclick="openFile()" style="cursor:pointer">
                                    <else/>
                                    <img class="ph-user" src="__PUBLIC__/img/wutu.png" alt="" width="80" height="80" onclick="openFile()" style="cursor:pointer">
                                </if>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">首页分类名称</label>
                            <div class="col-sm-10">
                                <input id="name" name="name" value="{$list.name}" type="text"  class="form-control" placeholder="请输入首页分类名称">
                            </div>
                        </div>
                        <input type="hidden"  name="id" value="{$list.id}">
                        <input type="hidden" name="img" value="{$list.img}">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label"></label>
                            <div class="col-sm-10">
                                <input  type="button" id="tianjia" class="btn btn-theme" value="保存">
                                <input  type="reset" class="btn btn-warning" value="重置">
                            </div>
                        </div>
                    </form>
                </div>
            </div><!-- col-lg-12-->
        </div><!-- /row -->
    </section>
</section>
<!--footer-->
<include file="Public:footer"/>
<!--footer-->
<script type="text/javascript" src="__PUBLIC__/ui/lib/layer/2.4/layer.js"></script>
<script>
    if($("#one").is(":checked")){
        $("#a").show();
        $("#c").hide();
    }else if($("#two").is(":checked")){
        $("#c").show();
        $("#a").hide();
    }else{
        $("#a").show();
        $("#c").hide();
    }
    $("#status").change(function () {
        if($("#one").is(":checked")){
            $("#a").show();
            $("#c").hide();
        }
        if($("#two").is(":checked")){
            $("#c").show();
            $("#a").hide();
        }
    })
    $("#tianjia").click(function(){
        var form = new FormData(document.getElementById("type"));
        $.ajax({
            url:"{:U('checks')}",
            type:"post",
            data:form,
            processData:false,
            contentType:false,
            success:function(res){
                if(res.status == 1){
                    layer.open({
                        title: '分类添加/修改提示：',content: res.info
                    });
                }
                if(res.status == 2){
                    layer.open({
                        title: '分类添加/修改提示：',content: res.info
                    });
                }
            }
        });
    });
    //图片上传
    function openFile(){
        return  $("#avatar").click();
    }
    function PreviewImage(imgFile) {
        var filextension=imgFile.value.substring(imgFile.value.lastIndexOf("."),imgFile.value.length);
        var o=imgFile.files[0];
        filextension=filextension.toLowerCase();
        if ((filextension!='.jpg')&&(filextension!='.jpeg')&&(filextension!='.png')&&(filextension!='.bmp'))
        {

            imgFile.focus();
        }else if(o.size > 2097152){
            imgFile.focus();
        }
        else
        {
            var path;
            path=window.URL.createObjectURL(imgFile.files[0]);// FF 7.0以上
            $('.ph-user').attr({src:path});
        }
    }
</script>

</body>
</html>
